import logging
import time
import unittest
from webAutomation import utils
from webAutomation.other.home_page import HomeProxy
from webAutomation.page.login_page import LoginProxy
from webAutomation.utils import DriverUtil


class TestAddCabinet(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        cls.login_proxy = LoginProxy()
        cls.home_proxy = HomeProxy()

    @classmethod
    def tearDown(self) -> None:
        DriverUtil.quit_driver()

    def test01_add_cabinet_success(self):
        try:
            # 登录
            self.login_proxy.login("admin", "123")
            # 添加电柜
            self.home_proxy.add_cabinet(site_name="web自动化1号", address="深圳市南山区南山智园最牛公司",
                                        cabinet_num="HD4812SYB2210628088",
                                        longitude="114.005499", latitude="22.595600")
            time.sleep(3)
            # 断言
            assert_result = utils.exit_text("HD4812SYB2210628088")
            self.assertTrue(assert_result)


        # 捕捉异常
        except Exception as e:
            # 截图
            utils.screenshot(self)
            # 输出日志
            logging.info("添加电柜出现异常：{}".format(e))
            raise


